package com.imau.brand.controller;

import com.alibaba.fastjson.JSON;
import com.imau.brand.bean.Brand;
import com.imau.brand.service.BrandService;
import com.imau.brand.service.impl.BrandServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/brandEdit")
public class BrandUpdateController extends HttpServlet {

    /**
     * 初始化业务层对象
     */
    private BrandService brandService = new BrandServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1.获取前端发送的数据
        String jsonString = request.getReader().readLine();
        //2.转成Java对象
        Brand brand = JSON.parseObject(jsonString, Brand.class);
        //3.调用业务层方法保存
        boolean b = brandService.editBrand(brand);
        //4.响应结果
        response.getWriter().write(b + "");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
